<?php
/* 幼儿园简介，园地，导航 
 * 
 * */
namespace Home\Controller;
class IntroController extends ComController{
	//幼儿园简介
	public function index(){
		//已get方式接收幼儿园id
		$sc_id = isset($_GET['uid'])?(int)$_GET['uid']:'';
		if(empty($sc_id)){
			//参数错误，未传参
			$this->notice('','参数错误,请重新选择');
			die;
		}else{
			$where['uid']=$sc_id;
			$w['sc_id']=$sc_id;
			$w['status']=1;
		}
		//从member表中查询幼儿园简介
		$member = M('member');
		$data = $member->where($where)->field('uid,name,address,email,phone,content,lng,lat')->find();
		//查询园地信息
		//分页
		
		$corner = M('corner');
		$p= intval($_GET['p'])?$_GET['p']:1;
		$pagesize = 2;#每页数量
		$offset = $pagesize * ($p - 1);//计算记录偏移量
		$count = $corner->where($w)->count();
		$page=ceil($count/$pagesize);
		
		$info = $corner->where($w)->limit($offset.','.$pagesize)->order('add_time desc')->select();
		if(!empty($info)){
			foreach ($info as $key=>$val){
				$info[$key]['content']=explode('|', $val['content']);
			}
		}
		$this->assign('data',$data);
		$this->assign('info',$info);
		$this->assign('page',$page);
		$this->display();
	}
	//加载更多园地信息
	public function moreCorner(){
		$p = isset($_POST['p'])?(int)$_POST['p']:'';
		$id = isset($_POST['id'])?(int)$_POST['id']:'';
		$pagesize = 2;#每页数量
		$offset = $pagesize * ($p - 1);//计算记录偏移量
		$corner = M('corner');
		$w['sc_id']=$id;
		$w['status']=1;
		$info = $corner->where($w)->limit($offset.','.$pagesize)->order('add_time desc')->select();
		if(!empty($info)){
			foreach ($info as $key=>$val){
				$info[$key]['content']=explode('|', $val['content']);
			}
			$this->assign('info',$info);
		}
		$this->display('Intro/moreCorner');
	}
	//导航
	public function nav(){
		$id = isset($_GET['id'])?(int)$_GET['id']:'';
		if(!empty($id)){
			$where['uid']=$id;
			$member = M('member');
			$info = $member->where($where)->field('uid,lng,lat')->find();
			if(!empty($info)){
				$this->assign('info',$info);
			}else{
				//未查到幼儿园坐标信息
			}
		}else{
			//未接收到幼儿园id
		}
		$this->display();
	}
	
	/* 前台通知 */
	
	public function notice($url='',$msg=''){
	
		if(!empty($msg)){
			$data['msg']=$msg;
		}
		if(empty($url)){
			$data['url'] = $_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:"javascript:window.history.go(-1)";
		}else{
			$data['url']=$url;
		}
		$this->assign('data',$data);
		$this->display("Public:notice");
	
	}
	
}



